package com.shiguo365.market.display.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.shiguo365.market.R;
import com.shiguo365.market.application.MyApplication;
import com.shiguo365.market.display.base.BaseActivity;
import com.shiguo365.market.display.listener.NavigationFinishClickListener;
import com.shiguo365.market.display.util.ActivityCollector;
import com.shiguo365.market.display.util.ToolsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {

    @BindView(R.id.tv_vesion)
    TextView tv_vesion;

    @BindView(R.id.seeting_toolbar)
    protected Toolbar toolbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this); //ButterKnife初始化

        toolbar.setNavigationOnClickListener(new NavigationFinishClickListener(this));
        PackageManager pm = MyApplication.getAppContext().getPackageManager();
        PackageInfo pi = null;
        try {
            pi = pm.getPackageInfo(MyApplication.getAppContext().getPackageName(), 0);
            String currentVersionName = pi.versionName;
            tv_vesion.setText(currentVersionName);

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }


    }

    @OnClick(R.id.buttonUserLoginout)
    public void loginout(){
        ActivityCollector.finishAll();
        //用户注销登录
        SharedPreferences.Editor editor =getSharedPreferences("data", Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();
        Intent intent= new Intent(this,LoginActivity.class);
        startActivity(intent);
        this.finish();
    }

    @OnClick(R.id.buttonUpdate)
    public void updatecheck(){
        ToolsUtils.checkUpdate(this,true); //版本更新
    }
}
